package com.example.mallmanagement.controller;

import com.example.mallmanagement.domain.Order;
import com.example.mallmanagement.mapper.OrderMapper;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderMapper orderMapper;

    @GetMapping(path = "/findOrders/{userId}")
    @HystrixCommand(fallbackMethod = "findOrderFallback")
    public List<Order> findOrder(@PathVariable("userId") Integer userId){
        List<Order> orders = this.orderMapper.selectOrder(userId);
        return orders;
    }

    //针对上面熔断器发现的问题编写回调方法（参数和返回值要一样）
    public List<Order> findOrderFallback(Integer userId){
        List<Order> orders = new ArrayList<>();
        return orders;
    }
}
